<?php

// Copyright (c) 2012 Mirza Adipradhana
// THEME ABSTRACTION CLASS

abstract class Theme {

    private $mMenu;
    private $mUserName;
    private $mUserLevel;
    private $mPageMainUrl;

    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */
    /*  L O G I N  */

    //Menampilkan Halaman Login Page
    public function PrintLoginPage() {
        $tPage = "\n<div id=\"canvas\">\n";
        $tPage.= $this->GetLoginContainer();
        $tPage.= "\n</div>\n";

        echo $tPage;
    }

    //Membuat Container Login
    abstract function GetLoginContainer();

    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */

    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */
    /*  L O G I N  */

    //Menampilkan Halaman Login Page
    public function PrintActivationPage() {
        $tPage = "\n<div id=\"canvas\">\n";
        $tPage.= $this->GetActivationContainer();
        $tPage.= "\n</div>\n";

        echo $tPage;
    }

    //Membuat Container Login
    abstract function GetActivationContainer();

    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */



    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */
    /*  M A I N  P A G E  */
    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */

    /*          OUTPUT             */
    /* ===== *//* ===== *//* ===== */

    //Menampilkan Halaman Main Page
    public function PrintMainPage(&$_ERRHANDLER) {
        $tPageHeader = $this->GetHeaderContainer();
        $tPageFooter = $this->GetFooterContainer();

        echo "\n<div id=\"canvas\">\n";
        echo $tPageHeader;
        $this->GetPageContainer($_ERRHANDLER);

        echo $tPageFooter;
        echo "\n</div>\n";
    }

    //Menampilkan Halaman Grafik Page
    public function PrintMainGraphicPage(&$_ERRHANDLER) {
        $tPageFooter = $this->GetFooterContainer();

        echo "\n<div id=\"canvas\">\n";
        $this->GetGraphicPageContainer($_ERRHANDLER);
        echo $tPageFooter;
        echo "\n</div>\n";
    }

    abstract function GetHeaderContainer();

    abstract function GetPageContainer(&$_ERRHANDLER);

    abstract function GetFooterContainer();
    /* ===== *//* ===== *//* ===== */

    /*          MUTUATOR           */
    /* ===== *//* ===== *//* ===== */

    public function SetPage($pUrl) {
        $this->mPageMainUrl = $pUrl;
    }

    public function GetPage() {
        return $this->mPageMainUrl;
    }

    public function SetInfoUserName($pUser) {
        $this->mUserName = $pUser;
    }

    public function SetInfoUserLevel($pLevel) {
        $this->mUserLevel = $pLevel;
    }

    public function GetInfoUserName() {
        return $this->mUserName;
    }

    public function GetInfoUserLevel() {
        return $this->mUserLevel;
    }

    public function GetFooter() {
        $tPage = "<p><b>" . APPLICATION_NAME . "</b> " . APPLICATION_VERSION . ". " . APPLICATION_COPYRIGHT . "</p>";
        $tPage.= "<p>" . APPLICATION_DEVELOPER . "</p>";
        return $tPage;
    }

    /* ===== *//* ===== *//* ===== */


    /*            MENU             */
    /* ===== *//* ===== *//* ===== */

    private function CalibratingMenu($pMenu) {
        $tRes = array();
        $tRes["MASTER DATA"] = array();
        $tRes["INISIALISASI"] = array();
        $tRes["VERIFIKASI"] = array();
        $tRes["PERSETUJUAN"] = array();

        foreach ($pMenu as $tTitle => $tValue) {
            if ($tTitle == "MASTER DATA") {
                $tRes["MASTER DATA"] = $tValue;
            } else if ($tTitle == "INISIALISASI") {
                $tRes["INISIALISASI"] = $tValue;
            } else if ($tTitle == "VERIFIKASI") {
                $tRes["VERIFIKASI"] = $tValue;
            } else if ($tTitle == "PERSETUJUAN") {
                $tRes["PERSETUJUAN"] = $tValue;
            } else {
                $tRes[$tTitle] = $tValue;
            }
        }
        return $tRes;
    }

    public function GetMenu() {
        return $this->mMenu;
    }

    public function SetMenu($pMenu) {
        $tCount = count($pMenu);
        $pMenu = $this->CalibratingMenu($pMenu);
        $this->mMenu.= "<ul>";
        $i = 0;
        foreach ($pMenu as $tTitle => $tValue) {
            $tIsLast = false;
            //if (($i + 1) == $tCount)
              //  $tIsLast = true;

            //CHECK SUB MENU
            $tSub = '';
            if (is_array($tValue)) {
                $tCountSub = count($tValue);
                $j = 0;
                $tIsLastSub = false;
                foreach ($tValue as $tRes) {
                    //CHECK: Apakah submenu? submenu != title
                    $tTarget = $tRes[Link];
                    if (strtoupper($tRes[Caption]) != strtoupper($tTitle)) {
                        if (($j + 1) == $tCountSub)
                            $tIsLastSub = true;

                        $tSub.= "<li class=\"submenu" . ($tIsLastSub ? " last" : "") . "\" href=\"" . $tTarget . "\">" . $tRes[Caption] . "</li>";
                        $j++;
                    }
                }
            }

            //JIKA SUB=EMPTY, artinya menu tidak memiliki sub menu sehingga nilai link diletakkan pada title
            if (empty($tSub)) {
                if($tTitle != "MASTER DATA" && $tTitle != "PERSETUJUAN")
                    $this->mMenu.= "<li class=\"title " . ($tIsLast ? " last" : "") . "\" href=\"" . $tTarget . "\" >";
            }
            else
                $this->mMenu.= "<li class=\"title " . ($tIsLast ? " last" : "") . "\" >";

            //if($tTitle!="VERIFIKASI" || $tTitle!="PERSETUJUAN")
            if($tTitle != "MASTER DATA" && $tTitle != "PERSETUJUAN")
                $this->mMenu.= "<h3>" . strtoupper($tTitle) . "</h3>";

            if (!empty($tSub))
                $this->mMenu.= "<ul>" . $tSub . "</ul>";
            
            if($tTitle != "MASTER DATA" && $tTitle != "PERSETUJUAN")
                $this->mMenu.= "</li>";
            $i++;
        }
        $this->mMenu.= "</ul>";
    }

    /* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== *//* ===== */

    public function PrintRedirectingPage() {
        $tOutput = "\n<div id=\"Redirecting-Overlay\">\n";
        $tOutput.= "</div>\n";
        $tOutput.= "<div id=\"Redirecting-Container\">\n";
        $tOutput.= "\t<div style=\"\">" .
                "\t\t<h3 style=\"\">Redirecting..</h3>\n" .
                "\t\t<img src=\"" . THEME_IMAGES_PATH . "login-loading.gif\" />" .
                "\t</div>\n";
        $tOutput.= "</div>\n";
        echo $tOutput;
    }

}

?>
